package user

import (
	"x-admin/backend/internal/middleware"

	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
)

// RegisterRoutes 注册用户管理路由
func RegisterRoutes(r *gin.RouterGroup, db *gorm.DB) {
	// 创建依赖
	repo := NewRepository(db)
	service := NewService(repo)
	handler := NewHandler(service)

	// 创建权限路由组
	userGroup := middleware.NewPermissionGroup(r.Group("/users"), db)
	{
		userGroup.GET("", "user:list", handler.List)                                        // 获取用户列表
		userGroup.GET("/:id", "user:view", handler.GetByID)                                 // 获取用户详情
		userGroup.POST("", "user:create", handler.Create)                                   // 创建用户
		userGroup.PUT("/:id", "user:update", handler.Update)                                // 更新用户
		userGroup.DELETE("/:id", "user:delete", handler.Delete)                             // 删除用户
		userGroup.POST("/:id/reset-password", "user:reset_password", handler.ResetPassword) // 重置密码
	}
}
